home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / M / MacRecorder® HackersToolkit.cpt / SoundSample.c < prev    next >
C/C++ Source or Header  |  1989-11-21  |  3KB  |  126 lines

  1. /* Copyright © 1989  Farallon Computing, Inc */
  2.  
  3. #include "Sound.h"
  4. #include "DialogUtils.h"
  5.  
  6. #define        NIL     0
  7.  
  8. /* dialog items */
  9. enum
  10. {
  11.     dDone = 1,
  12.     dRecord,
  13.     dPlay,
  14.     dModemPort,
  15.     dPrinterPort
  16. };
  17.  
  18. main()
  19. {
  20.     DialogPtr    myDialog;
  21.     short        itemHit = 0;
  22.     Handle        theSound = 0;
  23.     short        whichPort;
  24.     
  25.     InitMac();    /* initialize managers */
  26.     
  27.     /* no main event loop - just put up a modal dialog */
  28.     
  29.     myDialog = GetNewDialog( 128, 0, -1);
  30.     
  31.     /* do initialization for the dialog */
  32.     OutlineDefaultButton(    myDialog);
  33.     
  34.     whichPort = modemPort;                    /* default value */
  35.     SetRadioButton( myDialog, dModemPort);    /* place bullet in radio button */
  36.     
  37.     /* disable play until we get a sound to play */
  38.     UnHiliteDialogItem( myDialog, dPlay);
  39.     
  40.     /* now ready to run the dialog */
  41.     while( itemHit != dDone)
  42.     {
  43.         ModalDialog( NIL, &itemHit);
  44.         
  45.         switch( itemHit)
  46.         {
  47.             case    dRecord:
  48.                 /* first, dispose of previous sound, if any */
  49.                 if (theSound != 0)
  50.                     DisposHandle( theSound);
  51.                 
  52.                 /*
  53.                 **    UnHiliteDialogItem buttons while recording
  54.                 */    
  55.                 UnHiliteDialogItem( myDialog, dRecord);
  56.                 UnHiliteDialogItem( myDialog, dPlay);
  57.                 
  58.                 /* get largest possible handle while leaving 2K around */
  59.                 theSound = GetBigHandle( 2);
  60.                 if (theSound == 0)
  61.                 {
  62.                     SysBeep(1);        /* could not get the memory */
  63.                 }
  64.                 else
  65.                 {
  66.                     short    result;
  67.                     
  68.                     /*
  69.                     **    note:
  70.                     **        Record() will shrink the size of the
  71.                     **        Sound Handle down when it's done recording
  72.                     **        if the full amount of available memory in
  73.                     **        the Handle is not used when recording
  74.                     */
  75.                     result = Record( theSound, whichPort);
  76.                     if (result == recordErr)
  77.                     {
  78.                         /* recording error */
  79.                         SysBeep(1);
  80.                         DisposHandle( theSound);
  81.                         theSound = 0;
  82.                     }
  83.                     else
  84.                     {
  85.                         /* play ok now */
  86.                         HiliteDialogItem( myDialog, dPlay);
  87.                     }
  88.                 }
  89.                 /* record ok now */
  90.                 HiliteDialogItem( myDialog, dRecord); 
  91.                 break;
  92.                 
  93.             case    dPlay:
  94.                 /* UnHiliteDialogItem buttons while playing  */    
  95.                 UnHiliteDialogItem( myDialog, dRecord);
  96.                 UnHiliteDialogItem( myDialog, dPlay);
  97.  
  98.                 /* use toolbox's Sound Manager to play the sound */    
  99.                 SndPlay( NIL, theSound, false);    
  100.  
  101.                 /* Ok to Record / Play again */    
  102.                 HiliteDialogItem( myDialog, dRecord);
  103.                 HiliteDialogItem( myDialog, dPlay);
  104.                 break;    
  105.                 
  106.             case    dModemPort:
  107.                 ToggleRadioButtons( myDialog, dPrinterPort, dModemPort);
  108.                 whichPort = modemPort;
  109.                 break;
  110.                 
  111.             case    dPrinterPort:
  112.                 ToggleRadioButtons( myDialog, dModemPort, dPrinterPort);
  113.                 whichPort = printerPort;
  114.                 break;
  115.         }
  116.     }
  117.     
  118.     /* clean-up */
  119.     DisposDialog( myDialog);
  120.     
  121.     /* dispose of sound, if any */
  122.     if (theSound != 0)
  123.         DisposHandle( theSound);
  124. }
  125.  
  126.